package com.shz.appletsapi.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shz.appletsapi.model.po.MineVersion;
import com.shz.appletsapi.model.vo.MinerVersionVo;
import com.shz.appletsapi.repository.MineVersionRepository;

@Service
public class MineVersionService {
	
	@Autowired
	private MineVersionRepository mineVersionRepository;
	
	
	public MinerVersionVo findVersion(String tsid) {
		MineVersion mineVersion = mineVersionRepository.findOne(1);
		MinerVersionVo minerVersionVo =new MinerVersionVo();
		minerVersionVo.setTsid(tsid);
		minerVersionVo.setTVersion(mineVersion.getVesion());
		minerVersionVo.setDownUrl(mineVersion.getDownUrl());
		return minerVersionVo;
	}
	
	public Boolean  isVersionUpdate(String version) {
		MineVersion mineVersion	 = mineVersionRepository.findOne(1);
		if(mineVersion == null ) return null;
		String str1 = deleteString0(version,'.');
		String str2 = deleteString0(mineVersion.getVesion(),'.');
		if(Integer.valueOf(str2) > Integer.valueOf(str1))  return true;
		return false;	
	}
	
	
	
	 public static String deleteString0(String str, char delChar){
	        String delStr = "";
	        for (int i = 0; i < str.length(); i++) {
	            if(str.charAt(i) != delChar){
	                delStr += str.charAt(i);
	            }
	        }
	        return delStr;
	    }

}
